﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="OFactoryRenovationList.aspx.cs" Inherits="IHISCETeim.Web.MachineSys.MacModel.OFactoryRenovationList" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="/MachineSys/EasyUI/themes/default/easyui.css"/>
	<link rel="stylesheet" type="text/css" href="/MachineSys/EasyUI/themes/icon.css" />
	<script type="text/javascript" src="/MachineSys/js/jquery-1.7.2.min.js"></script>   
	<script type="text/javascript" src="/MachineSys/EasyUI/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/MachineSys/EasyUI/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/MachineSys/EasyUI/easyui-formatter_20140718.js?v2"></script>
     <link href="/MachineSys/themes/css/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
    <script src="/MachineSys/js/DWZ/jquery.autocomplete.js" type="text/javascript"></script>
    <script src="/MachineSys/js/DWZ/jquery.inputValue.js" type="text/javascript"></script>
    <script type="text/javascript">
        ///自适应宽高
        $(window).resize(function(){		    
            $("#tab_list").datagrid({
                width: '100%',
                height: $(parent.document).find(".tabsPageContent").height() - 11 > 0 ? $(parent.document).find(".tabsPageContent").height() - 11 : 500,
            }); 
        });
        //权限处理
        var $powers={
            "r查看":<%=HasPowerEasyUI(IHISCETeim.Web.Permission.查看) %>,
            "r新增":<%=HasPowerEasyUI(IHISCETeim.Web.Permission.新增) %>,
            "r审核":<%=HasPowerEasyUI(IHISCETeim.Web.Permission.修改) %>,
            "r删除":<%=HasPowerEasyUI(IHISCETeim.Web.Permission.删除) %>,
            "r导出":<%=HasPowerEasyUI(IHISCETeim.Web.Permission.导出) %>            
            };

        $(document).ready(function () {          
            //权限处理
            var $tab_toolbar=$("#tab_toolbar");
            $tab_toolbar.find("a").each(function(){
                var $per=$(this).attr("Permission");
                var pt= $powers[$per]==undefined || null?true:$powers[$per];
                $(this).linkbutton(pt?'enable': 'disable');
               
                if($(this).attr("menu")!=undefined && (pt==false))
                {
                    $(this).menubutton({
                        disabled:true
                    });
                }
                 
            })
           
            //自动完成
            $(".autocomplete").each(function () {
                var $this = $(this);
                var url = unescape($this.attr("autocompletehref"));
                $this.autocomplete(url);
            });
            //加载数据
            InitGird();  
            //加载通用查询字段
            var fields = $('#tab_list').datagrid('getColumnFields',true);
            for(var i=0; i<fields.length; i++){
                $('<option value="'+fields[i]+'" />').html($('#tab_list').datagrid('getColumnOption',fields[i]).title).appendTo($("#search_commfields"));
            }
            fields = $('#tab_list').datagrid('getColumnFields');
            for(var i=0; i<fields.length; i++){
                $('<option value="'+fields[i]+'" />').html($('#tab_list').datagrid('getColumnOption',fields[i]).title).appendTo($("#search_commfields"));
            }
        })
        //加载列表数据
        function InitGird() {
            $('#tab_list').datagrid({               
                url: location.href, //请求数据的页面
                sortName: 'ID', //排序字段
                sortOrder: 'desc', //排序类型
                idField: 'ID', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度    
                height: $(parent.document).find(".tabsPageContent").height() - 11 > 0 ? $(parent.document).find(".tabsPageContent").height() - 11 : 500,
                nowrap: true, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                singleSelect: true, //是否只能选中一条
                remoteSort: true, //定义是否从服务器给数据排序
                frozenColumns: [[//冻结的列，不会随横向滚动轴移动
                    { title: '单号', field: 'DocNum', width: 100,rowspan:2, sortable: true,formatter:function(value, row, index){
                        if(row.DocNum==undefined)
                            return "合计:";
                        return '<a style=" font-weight:bold;" title="导出" href="<%=ExportExcelWebUrl %>/MacModel/OFactoryRenovationSing.aspx?ID='+row.ID+'" target="_blank" >'+value+'</a>';//事件处理
                    }},
                    { title: '机号', field: 'SerialNumber', width: 100,rowspan:2, sortable: true},
                    { title: '类型', field: 'MachineProperty', width: 100,rowspan:2, sortable: true},                	
                    { title: '返厂日期', field: 'ReturnDate', width: 100,rowspan:2, sortable: true,formatter:formatterdate },    
                    { title: '经销商', field: 'AgentName', width: 100,rowspan:2, sortable: true},     
                ]],
                columns: [
                    [
                     {title: '工作小时', field: 'WorkTime', width: 90,rowspan:2, sortable: true,align:'right'},                  
                     {title: '翻新内容', field: 'RenovationContent', width: 100,rowspan:2,sortable: true},
                     {title: '是否收费', field: 'IsCharges', width: 100, rowspan:2,sortable: true,formatter:function(value, row, index){
                         if(value== undefined){
                             return "";
                         }
                         if(value){
                             return "是";
                         }else{
                             return "否";
                         }
                     }},  
                     {title: '发行时间', field: 'IssueDate', width: 100 ,rowspan:2,sortable: true,formatter:formatterdate},
                     {title: '需求部门', field: 'DemandDept', width: 100 ,rowspan:2,sortable: true},
                     {title:'回购车信息',colspan:5},
                     <%if (HasPower(IHISCETeim.Web.Permission.厂内翻新机_查看全部))
                       {%>
                     {title:'翻新后信息',colspan:3},
                     {title:'二 次 销 售',colspan:3},
                     {title:'翻新成本',colspan:5},
                     {title:'翻新收入',colspan:5},
                      {title: '损益', field: 'Loss', width: 100 ,rowspan:2,sortable: true},
                     {title: '备注', field: 'Remark', width: 100 ,rowspan:2,sortable: true},
                    <%}%>
                    ],
                    [                     
                     {title: '回购成本（不含税）', field: 'BuyBackCost', width: 120 ,sortable: true},
                     {title: '运费', field: 'Freight', width: 100 ,sortable: true},
                     {title: '第三方协议', field: 'IsThreeParty', width: 100 ,sortable: true,formatter:function(value, row, index){
                         if(value== undefined){
                             return "";
                         }
                         if(value){
                             return "<a href='#' onclick='onThreePartyClick("+row.ID+")'>有</a>";
                         }else{
                             return "无";
                         }
                     }},
                     {title: '是否可开票', field: 'IsInvoice', width: 100 ,sortable: true,formatter:function(value, row, index){
                         if(value== undefined){
                             return "";
                         }
                         if(value){
                             return "是";
                         }else{
                             return "否";
                         }
                     }},
                     {title: '备注', field: 'BuyRemark', width: 100 ,sortable: true},
                       <%if(HasPower(IHISCETeim.Web.Permission.厂内翻新机_查看全部)){%>
                     {title: '完成日期', field: 'CompDate', width: 100 ,sortable: true},
                     {title: '翻新后小时', field: 'CompWorkTime', width: 100 ,sortable: true},
                     {title: '备注', field: 'CompRemark', width: 100 ,sortable: true},

                     {title: '新经销商', field: 'NewAgentName', width: 100 ,sortable: true},
                     {title: '合同号', field: 'NewContractNo', width: 100 ,sortable: true},
                     {title: '合同金额', field: 'NewContractAmount', width: 100 ,sortable: true},

                     {title: '服务领用配件成本', field: 'CostPart', width: 100 ,sortable: true},
                     {title: '营业部领用配件成本', field: 'CostYY', width: 100 ,sortable: true},
                     {title: '旧件残值', field: 'CostOldPieces', width: 100 ,sortable: true},
                     {title: '其他费用', field: 'CostOther', width: 100 ,sortable: true},
                     {title: '成本合计', field: 'CostTotal', width: 100 ,sortable: true},

                     {title: '开票日期', field: 'InVoiceDate', width: 100 ,sortable: true,formatter:formatterdate},
                     {title: '配件收入', field: 'InPart', width: 100 ,sortable: true},
                     {title: '工时收入', field: 'InWork', width: 100 ,sortable: true},
                     {title: '未税金额', field: 'InTotal', width: 100 ,sortable: true},
                     {title: '凭证号', field: 'InVoucher', width: 100 ,sortable: true} 
                     <%}%>
                    ]
                ],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "query" },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: <%=numPerPage %>, //默认一页数据条数
                pageList:<%=SetnumPerPage() %>,
                rownumbers: true, //行号
                showFooter: true,
                onHeaderContextMenu: function(e, field){
                    e.preventDefault();
                    if (!$('#tmenu').length){
                        createColumnMenu();
                    }
                    $('#tmenu').menu('show', {
                        left:e.pageX,
                        top:e.pageY
                    });
                },
                onRowContextMenu:function(e,rowIndex,rowData)
                {
                    e.preventDefault();
                    if (!$('#tmenu').length){
                        createColumnMenu();
                    }
                    $('#tmenu').menu('show', {
                        left:e.pageX,
                        top:e.pageY
                    });
                }
            });

        }  
        /*显示列*/
        var ColumnFields={'RealName':"姓名"};
        function createColumnMenu(){
            var tmenu = $('<div id="tmenu" style="width:150px;"></div>').appendTo('body');
            var fields = $('#tab_list').datagrid('getColumnFields');
            for(var i=0; i<fields.length; i++){
                $('<div data-options="name:\''+fields[i]+'\',iconCls:\'icon-ok\'" />').html($('#tab_list').datagrid('getColumnOption',fields[i]).title).appendTo(tmenu);
            }
            tmenu.menu({
                onClick: function(item){
                    if (item.iconCls=='icon-ok'){                       
                        $('#tab_list').datagrid('hideColumn', item.name);
                        tmenu.menu('setIcon', {
                            target: item.target,
                            iconCls: 'icon-empty'
                        });
                    } else {
                        $('#tab_list').datagrid('showColumn', item.name);
                        tmenu.menu('setIcon', {
                            target: item.target,
                            iconCls: 'icon-ok'
                        });
                    }
                }
            });
        }
    </script>
    <script>
        //操作功能JS

        //打开高级查找窗口
        function onAdjSearch() {
            $("#tab_search").dialog("open");
            $("#search-buttons").find("#btn_search").one("click", function () {               
                var query = $("#tab_search").serializeJSON(); // GetInputData("tab_search", "query");
                query.action = "query";
                $('#tab_list').datagrid("options").queryParams = query;
                $('#tab_list').datagrid('load');
                $("#tab_search").dialog("close");
                return false;
            
            });
        }       

        function onView2Click(type)
        {
            var query = $("#tab_search").serializeJSON(); // GetInputData("tab_search", "query");
            query.action = "query";
            if(type==0){//回购车清单
                query.MachineProperty = "回购车";
            }
            if(type==1){
                query.OnlyWeiWC = "1";
            }
            if(type==2){
                query.OnlyHGWXS = "1";
            }
            $('#tab_list').datagrid("options").queryParams = query;
            $('#tab_list').datagrid('load');
            $("#tab_search").dialog("close");
            return false;
        }

        function onThreePartyClick(id)
        {
            var rel = "OFactoryRenovationThreeParty";
            var url = "MacModel/OFactoryRenovationThreeParty.aspx?id=" + id;
            var title = "三方协议附件上传";
            var options = { width: 450, height: 350, max: false, mask: true, maxable: false, minable: false, fresh: true, resizable: false, drawable: true };
            top.$.pdialog.open(url, rel, title, options);
            //top.navTab.openTab(rel, url, { title: title, fresh: true, external: false });
            return false;
        }
        //新增
        function onAddClick() {
            var rel = "OFactoryRenovationAdd";
            var url = "MacModel/OFactoryRenovationAdd.aspx";
            var title = "新增翻新整机信息";
            var options = { width: 850, height: 450, max: false, mask: true, maxable: false, minable: false, fresh: true, resizable: false, drawable: true };           
            top.navTab.openTab(rel, url, { title: title, fresh: true, external:false });
            return false;
        }
        //查看
        function onViewClick() {
            var row = $('#tab_list').datagrid('getSelected')
            if (row == null) {
                $.messager.alert('提示', '请先选择一条要查看的记录');
                return false;
            }

            var ID = row.ID;

            var rel = "OFactoryRenovationView";
            var url = "MacModel/OFactoryRenovationView.aspx?id=" + ID;
            var title = "查看";
            var options = { width: 850, height: 450, max: false, mask: true, maxable: false, minable: false, fresh: true, resizable: false, drawable: true };
            //top.$.pdialog.open(url, rel, title, options);
            top.navTab.openTab(rel, url, { title: title, fresh: true, external: false });

            $('#tab_list').datagrid('unselectAll')//取消选中,不然会直接选中上次的数据
            return false;
        }
        //修改
        function onEditClick() {
            var row = $('#tab_list').datagrid('getSelected')
            if (row == null) {
                $.messager.alert('提示', '请先选择一条要修改的记录');
                return false;
            }

            var ID = row.ID;

            var rel = "OFactoryRenovationEdit";
            var url = "MacModel/OFactoryRenovationEdit.aspx?id=" + ID;
            var title = "修改整机翻新信息";
            var options = { width: 850, height: 450, max: false, mask: true, maxable: false, minable: false, fresh: true, resizable: false, drawable: true };
            //top.$.pdialog.open(url, rel, title, options);
            top.navTab.openTab(rel, url, { title: title, fresh: true, external: false });

            $('#tab_list').datagrid('unselectAll')//取消选中,不然会直接选中上次的数据
            return false;
        }

        //删除
        function onDelClick() {
            var row = $('#tab_list').datagrid('getSelected')
            if (row == null) {
                $.messager.alert('提示', '请先选择要删除的信息');
                return false;
            }
            $.messager.confirm('提示', '您确认要删除此记录', function (r) {
                if (r) {
                    var ID = row.ID;
                    var url = "MacModel/OFactoryRenovationList.aspx?action=delrow&id=" + ID;
                    top.ajaxTodo(url, "");
                    $("#tab_list").datagrid("load");

                }
            });
            $('#tab_list').datagrid('unselectAll')//取消选中,不然会直接选中上次的数据
            return false;
        }
        function onExplorClick()
        {
            var href = "<%= ExportExcelWebUrl%>/MacModel/FTradeExportHKTSH.aspx" ;
            top.window.open(href, "");
        }
             
    </script>
</head>
<body style="margin:2px;" >
   
    <div id="tab_list" ></div>
    <div id="tab_toolbar" style="padding:2px;">
       <a href="#" title="高级查找" class="easyui-linkbutton" iconcls="icon-search" plain="true" onclick="return　onAdjSearch(this);" Permission="">查找</a>        
       <a href="#" title="回购车清单" class="easyui-linkbutton" iconcls="icon-search" plain="true" onclick="return　onView2Click(0);" Permission="r查看">回购车清单</a>
       <a href="#" title="回购车清单" class="easyui-linkbutton" iconcls="icon-search" plain="true" onclick="return　onView2Click(2);" Permission="r查看">已回购未销售清单</a>
       <a href="#" title="未完成清单" class="easyui-linkbutton" iconcls="icon-search" plain="true" onclick="return　onView2Click(1);" Permission="r查看">未完成清单</a>

        <a href="#" title="查看" class="easyui-linkbutton" iconcls="icon-save" plain="true" onclick="return　onViewClick();" Permission="r查看">查看</a>        
        <a href="#" title="新增" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="return onAddClick()" Permission="r新增">新增</a>   
       <a href="#" title="修改" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="return onEditClick()" Permission="r修改">修改</a>   
    
       <a href="#" title="删除" class="easyui-linkbutton" iconcls="icon-remove" plain="true" onclick="return　onDelClick();" Permission="r删除">删除</a> 
       <a href="javascript:void(0)"  class="easyui-linkbutton"  iconCls="icon-btnDown" Permission="r导出"  plain="true" onclick="return onExplorClick()">导出完整表</a>
    </div> 

  

    <div id="tab_search" title="查询条件" style=" height:250px; width:500px;" class="easyui-dialog" modal="true" closed="true" buttons="#search-buttons">
        <table class="table_search" width="100%" style=" line-height:21px;">
            <tr>
                <td>单号:</td>
                 <td colspan="3"><input  name="DocNum"  /></td>
            </tr>          
            <tr>
                <td>代理商:</td>
                <td><input  name="AgentName" value="" /></td>
                <td>机号:</td>
                <td><input  name="SerialNumber" value="" /></td>
            </tr>
            <tr>
                <td>机器性质/类型：</td>
                <td colspan="3">
                     <select name="MachineProperty" >
                         <option value="">所有...</option>
                        <option value="样机">样机</option>
                        <option value="退机">退机</option>
                        <option value="返修车">返修车</option>
                        <option value="回购车">回购车</option>
				    </select>
                </td>
            </tr>
            <tr>
                <td>只显示未完成</td>
                <td colspan="3">
                    <input type="checkbox" name="OnlyWeiWC" value="1" />
                </td>
            </tr>
             <tr>
                <td>只显示已回购未销售的</td>
                <td colspan="3">
                    <input type="checkbox" name="OnlyHGWXS" value="1" />
                </td>
            </tr>
        </table>
        <div id="search-buttons">
            <a id="btn_search" href="javascript:;" class="easyui-linkbutton" iconcls="icon-search" plain="true">提交</a> 
            <a href="javascript:;" class="easyui-linkbutton" onclick="$('#tab_search').dialog('close');return false;" iconcls="icon-cancel" plain="true">取消</a>
        </div>
    </div>
       
</body>
</html>